//
//  PictureCell.m
//  qiuShiJiangHu
//
//  Created by xalo on 16/1/25.
//  Copyright © 2016年 糗事江湖项目组. All rights reserved.
//

#import "PictureCell.h"
#import "ImageModel.h"
#import "UIImageView+WebCache.h"
@interface PictureCell ()

@property (strong, nonatomic) IBOutlet UIImageView *iconImage;

@property (strong, nonatomic) IBOutlet UILabel *loginLabel;


@property (strong, nonatomic) IBOutlet UIImageView *contentImage;

@property (strong, nonatomic) IBOutlet UILabel *laughLabel;


@property (strong, nonatomic) IBOutlet UILabel *commentLabel;

@property (strong, nonatomic) IBOutlet UILabel *shareLabel;

@property (strong, nonatomic) IBOutlet UIButton *laughButton;

@property (strong, nonatomic) IBOutlet UIButton *unlaughButton;



@end



@implementation PictureCell


-(void)setContentViewWithModel:(ImageModel *)model
{
    self.loginLabel.text = model.login;
    
    self.contentLabel.text = model.content;
    
    NSInteger number = model.Id;
    
    NSString *numStr = [NSString stringWithFormat:@"%ld",number];
    
    NSString *num1 = nil;
    
    if (numStr.length == 8) {
        
        num1 = [numStr substringWithRange:NSMakeRange(0, 4)];
        
    }else if(numStr.length == 7)
    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 3)];
        
    }else if(numStr.length == 6)
    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 2)];
        
    }else 

    {
        num1 = [numStr substringWithRange:NSMakeRange(0, 1)];
        
    }
    
    NSString *url = [NSString stringWithFormat:@"http://pic.qiushibaike.com/system/avtnew/%@/%@/thumb/%@",num1,numStr,model.icon];
    
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@""]];
    self.iconImage.layer.cornerRadius = 18;
    
    self.iconImage.layer.masksToBounds = YES;
    
   
    
//    NSString *str = [NSString stringWithFormat:@"%ld",model.ID];
    
    NSString *str = model.image;
    
    NSString *str1 = [str substringWithRange:NSMakeRange(3, 9)];
    
    
    NSString *str2 = [str1 substringWithRange:NSMakeRange(0, 5)];
    
    NSString *url1 = [NSString stringWithFormat:@"http://pic.qiushibaike.com/system/pictures/%@/%@/medium/%@",str2,str1,model.image];
    
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:url1] placeholderImage:[UIImage imageNamed:@"Icon@2x"]];

    self.laughLabel.text=[NSString stringWithFormat:@"%@",model.votes[@"up"]];
    
    self.commentLabel.text=[NSString stringWithFormat:@"%ld",model.comments_count];
    
    self.shareLabel.text=[NSString stringWithFormat:@"%ld",model.share_count];

}








- (IBAction)clickLaughButton:(UIButton *)sender {
    
    NSInteger number = [self.laughLabel.text integerValue];
    
    number++;
    
    self.laughLabel.text = [NSString stringWithFormat:@"%ld",number];

    
}


- (IBAction)clickUnlaughButton:(UIButton *)sender {
    
    NSInteger number = [self.laughLabel.text integerValue];
    
    number--;
    
    self.laughLabel.text = [NSString stringWithFormat:@"%ld",number];

    
}















- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
